package com.dmap.analysispoint.service.impl;

import com.dmap.analysispoint.constants.BurialPointConstant;
import com.dmap.analysispoint.service.DataPreparationService;
import com.dmap.analysispoint.service.OldDataManageService;
import com.dmap.analysispoint.service.PhoneInfoAnalysisService;
import com.dmap.base.units.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * \* @author:zhouhao
 * \* Date:26/06/2018
 * \* Description:未处理的老数据处理
 * \*
 */
@Service
public class OldDataManageServiceImpl implements OldDataManageService {

    @Resource
    private PhoneInfoAnalysisService phoneInfoAnalysisService;
    @Resource
    private DataPreparationService dataPreparationService;

    @Override
    public Integer oldDataManage(Long time) {
        if (time == null || time == 0) {
            return 0;
        }
        int success = 0;
        Long startTime = DateUtil.getDay0ByTime(phoneInfoAnalysisService.selectMinTime());
        Long endTime = startTime + BurialPointConstant.ONE_DAY_TIME_MILLISECONDS - 1;
        while(startTime < time){
            success = success + dataPreparationService.dataBoardAnalysis(startTime, endTime);
            startTime = startTime + BurialPointConstant.ONE_DAY_TIME_MILLISECONDS;
            endTime = endTime + BurialPointConstant.ONE_DAY_TIME_MILLISECONDS;
        }
        return success;
    }
}
